#!/usr/bin/env python

import hashlib
import os
import sys
from collections import OrderedDict

class Build():
    def __init__(self, build, delta):
        self.build = build
        self.delta = delta

    def get_checksum(self, file):
        return hashlib.sha1(file).hexdigest()

    def run(self):
        checksums = OrderedDict()
        delta_plugins = [plg for plg in os.listdir(self.delta)]
        print "Delta Package:"
        for plg in delta_plugins:
            print "%s\t%s" % (plg, self.get_checksum(plg))
            checksums[plg] = self.get_checksum(plg)
        print "\nBuild Package"
        for build_plugins in os.listdir(self.build):
            if build_plugins in delta_plugins:
                if checksums[build_plugins] == self.get_checksum(build_plugins):
                    print "%s\t%s\tTrue" % (build_plugins, self.get_checksum(build_plugins))
                else:
                    print "%s\t%s\tFalse" % (build_plugins, self.get_checksum(build_plugins))

def usage():
    print "Usage: build_checksum.py <path to build plugins dir> <path to dir of delta plugins>"

if __name__ == "__main__":
    if len(sys.argv) != 3:
        usage()
    else:
        checksums = Build(sys.argv[1], sys.argv[2])
        checksums.run()